

lst = [20, 30, 35, 46, 56, 57, 89, 92, 93]
# 问 57在列表中的位置是多少， 如果找不到返回-1

# 二分查找
def find(lst, target, left, right):
    if left <= right:
        middle = (left+right)//2
        if lst[middle] == target:
            return middle
        elif lst[middle]>target:
            return find(lst, target, left, middle-1)
        elif lst[middle]<target:
            return find(lst, target, middle+1, right)
    else:
        return -1


print(find(lst, 0, 0, len(lst) - 1))

#常规查找 
# def find(lst, target):
#     for i in range(len(lst)):
#         if lst[i] == target:
#             return i
#     return -1
#
# print(find(lst, 3))





# if 54 in lst:
#     print(lst.index(54))
# else:
#     print(-1)

